﻿using Microsoft.CSharp.Activities;
using System;
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WFExtended.Twitter.Activities.Designers;

namespace WFExtended.Twitter.Activities
{
    /// <summary>
    /// Returns a cursored collection of user objects for every user the specified user is following 
    /// </summary>
    [ToolboxBitmapAttribute(typeof(EntryPoint), "Resources.RelationshipToolbox.bmp")]
    [Designer(typeof(RelationshipDesigner))]
    [Description("Returns a cursored collection of user objects for every user the specified user is following.")]
    public class GetFriends : TwitterOperationInvoker<UserList>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="GetFriends"/> class.
        /// </summary>
        public GetFriends()
            : base("GetFriends")
        {
            Cursor = new InArgument<long>(new CSharpValue<long>("-1"));
            SkipStatus = new InArgument<bool>(new CSharpValue<bool>("false"));
            IncludeUserEntities = new InArgument<bool>(new CSharpValue<bool>("true"));
        }

        /// <summary>
        /// The ID of the user for whom to return results for.
        /// </summary>
        /// <value>
        /// The user ID.
        /// </value>
        [Browsable(true)]
        [Category("Properties")]
        [Description("The ID of the user for whom to return results for.")]
        public InArgument<string> UserID { get; set; }

        /// <summary>
        /// The screen name of the user for whom to return results for.
        /// </summary>
        /// <value>
        /// The username.
        /// </value>
        [Browsable(true)]
        [Category("Properties")]
        [Description("The screen name of the user for whom to return results for.")]
        public InArgument<string> Username { get; set; }

        /// <summary>
        /// Causes the results to be broken into pages of no more than 20 records at a time.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The cursor.
        /// </value>
        [Browsable(true)]
        [Category("Properties")]
        [Description("Causes the results to be broken into pages of no more than 20 records at a time.")]
        [RequiredArgument]
        public InArgument<long> Cursor { get; set; }

        /// <summary>
        /// When set to either true statuses will not be included in the returned user objects.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The skip status.
        /// </value>
        [Browsable(true)]
        [Category("Properties")]
        [Description("When set to either true statuses will not be included in the returned user objects.")]
        [RequiredArgument]
        public InArgument<bool> SkipStatus { get; set; }

        /// <summary>
        /// The user object entities node will be disincluded when set to false.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The include user entities.
        /// </value>
        [Browsable(true)]
        [Category("Properties")]
        [Description("The user object entities node will be disincluded when set to false.")]
        [RequiredArgument]
        public InArgument<bool> IncludeUserEntities { get; set; }

        /// <summary>
        /// Caches the metadata.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        protected override void CacheMetadata(System.Activities.NativeActivityMetadata metadata)
        {
            RuntimeArgument userIDArgument = new RuntimeArgument("UserID", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(UserID, userIDArgument);
            metadata.AddArgument(userIDArgument);

            RuntimeArgument usernameArgument = new RuntimeArgument("Username", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Username, usernameArgument);
            metadata.AddArgument(usernameArgument);

            RuntimeArgument cursorArgument = new RuntimeArgument("Cursor", typeof(long), ArgumentDirection.In, true);
            metadata.Bind(Cursor, cursorArgument);
            metadata.AddArgument(cursorArgument);

            RuntimeArgument skipStatusArgument = new RuntimeArgument("SkipStatus", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(SkipStatus, skipStatusArgument);
            metadata.AddArgument(skipStatusArgument);

            RuntimeArgument includeUserEntitiesArgument = new RuntimeArgument("IncludeUserEntities", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(IncludeUserEntities, includeUserEntitiesArgument);
            metadata.AddArgument(includeUserEntitiesArgument);

            base.CacheMetadata(metadata);
        }

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void Execute(System.Activities.NativeActivityContext context)
        {
            Parameters.Clear();

            Parameters.Add("userID", UserID);
            Parameters.Add("username", Username);
            Parameters.Add("cursor", Cursor);
            Parameters.Add("skipStatus", SkipStatus);
            Parameters.Add("includeUserEntities", IncludeUserEntities);

            base.Execute(context);
        }
    }
}
